const vertSrc =
`#version 300 es

layout (location = 0) in vec2 pos;

out vec2 tpos;

void main()
{
    gl_Position = vec4(pos.xy, 0.0, 1.0);
    tpos = (pos + 1.0) / 2.0;
}
`

const getFragSrc = (width, height) =>
`#version 300 es

precision mediump float;

const float WIDTH = ${width}.0, HEIGHT = ${height}.0;
const float BLOCK_WIDTH = 1.0 / WIDTH, BLOCK_HEIGHT = 1.0 / HEIGHT;

uniform sampler2D data;

in vec2 tpos;

out vec4 result;

void main()
{
    float xi = round(tpos.x * WIDTH), yi = round(tpos.y * HEIGHT);
    if (xi == 0.0 || xi == WIDTH - 1.0 || yi == 0.0 || yi == HEIGHT - 1.0)
    {
        result = vec4(0.0, 0.0, 0.0, 1.0);
        return;
    }
    float near = texture(data, vec2(tpos.x - BLOCK_WIDTH, tpos.y - BLOCK_HEIGHT)).x +
                 texture(data, vec2(tpos.x - BLOCK_WIDTH, tpos.y               )).x +
                 texture(data, vec2(tpos.x - BLOCK_WIDTH, tpos.y + BLOCK_HEIGHT)).x +
                 texture(data, vec2(tpos.x              , tpos.y - BLOCK_HEIGHT)).x +
                 texture(data, vec2(tpos.x              , tpos.y + BLOCK_HEIGHT)).x +
                 texture(data, vec2(tpos.x + BLOCK_WIDTH, tpos.y - BLOCK_HEIGHT)).x +
                 texture(data, vec2(tpos.x + BLOCK_WIDTH, tpos.y               )).x +
                 texture(data, vec2(tpos.x + BLOCK_WIDTH, tpos.y + BLOCK_HEIGHT)).x;
    if (near == 3.0)
    {
        result = vec4(1.0, 1.0, 1.0, 1.0);
    }
    else if (near < 2.0 || near > 3.0)
    {
        result = vec4(0.0, 0.0, 0.0, 1.0);
    }
    else
    {
        result = texture(data, tpos);
    }
}
`

const displayVertSrc = vertSrc

const displayFragSrc =
`#version 300 es

precision mediump float;

uniform sampler2D data;

in vec2 tpos;

out vec4 result;

void main()
{
    result = texture(data, tpos);
}
`
